﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using TerminationCall.Core;

namespace TerminationCall.Editor.Logic {
    public class BrushPainter : IPainter {

        private Point _startLocation;

        public BrushPainter(Point startLocation) {
            _startLocation = startLocation;
        }

        public int Size {
            private get;
            set;
        }

        public bool Autoborder {
            private get;
            set;
        }

        public EditorToolManager EditorToolManager {
            private get;
            set;
        }

        public PaintTile[] PaintTiles(Point location) {

            List<PaintTile> paintTiles = new List<PaintTile>();

            for (int x = 0; x < Size; x++) {
                for (int y = 0; y < Size; y++) {

                    if (Autoborder) {

                        AutoborderBrushPainter autoborderPainter = new AutoborderBrushPainter();
                        autoborderPainter.EditorToolManager = EditorToolManager;

                        Point point = new Point(x + location.X, y + location.Y);

                        paintTiles.AddRange(autoborderPainter.PaintTiles(point));

                    } else {

                        Point baseLocation = new Point(_startLocation.X % EditorToolManager.EditorTool.ChoosenTiles.Width, _startLocation.Y % EditorToolManager.EditorTool.ChoosenTiles.Height);

                        int currentX = (location.X - baseLocation.X) / EditorToolManager.EditorTool.ChoosenTiles.Width + x;
                        int currentY = (location.Y - baseLocation.Y) / EditorToolManager.EditorTool.ChoosenTiles.Height + y;

                        paintTiles.AddRange(EditorToolManager.SetChoosenTiles(baseLocation.X + currentX * EditorToolManager.EditorTool.ChoosenTiles.Width, baseLocation.Y + currentY * EditorToolManager.EditorTool.ChoosenTiles.Height));

                    }
                }
            }

            return paintTiles.ToArray();
        }





    }
}
